/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package main.java.cn.webrx;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Pattern;

/**
 * <p>Project: jse2204 - ReaderDemo
 * <p>Powered by webrx On 2022-09-23 17:38:22
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ReaderDemo {

    public static void main(String[] args) {
        Reader r = null;
        try {
            r = new FileReader("mi.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }finally{
            try {
                r.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        try(var out = new BufferedWriter(new FileWriter("mi.txt",true))) {
            out.write("hello world 中文程序\r\n");
            out.write("hello world 中文程序\r\n");
            out.write("hello world 中文程序\r\n");
            out.write("hello world 中文程序\r\n");
            out.write("hello world 中文程序\r\n");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        try(var show = new BufferedReader(new FileReader("mi.txt"))) {
            while(show.ready()) {
                System.out.println(show.readLine());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void test(String[] args) throws Exception {
        Reader reader = new FileReader("src.md");
        int c = 0;
        while((c = reader.read())!=-1){
            System.out.print((char)c);
        }


    }
}
